package java_thinking.unit_16;

import java.util.Arrays;
import java.util.Locale;

/**
 * @Desc:   编写一个方法，能够产生二维双精度型数组并加以初始化，数组的容量由
 *          方法的形式参数决定，其初始值必须落在另外两个形式参数所指定的区间内，
 *          编写第二个方法，打印出第一个方法所产生的数组，在main()中通过产生不同
 *          容量的数组并打印其内容来测试这两个方法；
 * @author: cww
 * @DateTime: 2019-04-08 22:41
 */

public class E03_TwoDDoubleArray {
    public static double[][] twoDoubleArray(int xLen,int yLen,double valStart,double valEnd) {
        double[][] array = new double[xLen][yLen];
        double increment = (valEnd - valStart)/(xLen*yLen);
        double val = valStart;
        for (int i =0;i<array.length;i++) {
            for (int j = 0;j<array[i].length;j++) {
                array[i][j] = val;
                val+=increment;
            }
        }
        return array;
    }
    public static void printArray(double[][] array) {
        for (int i = 0; i<array.length; i++){
            for (int j = 0; j<array[i].length; j++) {
                System.out.printf(Locale.US,"%.2f ",array[i][j]);
            }
            System.out.println();
        }
    }
    public static void main(String args[]) {
        double[][] twoD = twoDoubleArray(4, 6, 47.0, 99.0);
        printArray(twoD);
        System.out.println("**********************");
        double[][] twoD2 = twoDoubleArray(2, 2, 47.0, 99.0);
        printArray(twoD2);
        System.out.println("**********************");
        double[][] twoD3 = twoDoubleArray(9, 5, 47.0, 99.0);
        printArray(twoD3);

        System.out.println(Arrays.deepToString(new Object[3][3][3]));
    }
}
